﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using Petra.Gis;
using Petra.Gis.RenderingServices.Common;
using Petra.Gis.ReferenceSystemServices;


namespace Petra.Gis.RenderingServices.WPF
{

  public class InteractiveMap : PlanarOrthogonalMap
  {

    Bitmap _outBitmap;

    //mapscale = paper / coordinateMapWidth
    public InteractiveMap(int width, int height, ProjectedCoordinateSystem mapCrs, Size mapPixelSize, double mapScale)
      : base(width, height, mapCrs)
    {

      _legend = new Legend(this);

      _CoordinateReferenceSystem = mapCrs;

      //initialize output bitmap
      _outBitmap = new Bitmap(mapPixelSize.Width, mapPixelSize.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

      //init transformation
      DisplayTransformMatrix tmpMatrix = new DisplayTransformMatrix();
      tmpMatrix.Translate(mapCrs.DefaultEnvelope.Left, mapCrs.DefaultEnvelope.Bottom);
      double scale = (mapCrs.DefaultEnvelope.Right - mapCrs.DefaultEnvelope.Left) / mapPixelSize.Width;
      tmpMatrix.Scale(scale, (-1) * scale);

      _extent = new PlanarOrthogonalMapExtent(this, mapCrs.DefaultEnvelope, tmpMatrix);

      _renderer = (Renderer)new WPFRenderer(this, Graphics.FromImage(_outBitmap), tmpMatrix);
    }




    public WPFRenderer createRenderer(System.Type geomType)
    {

      return new WPFRenderer(this, Graphics.FromImage(_outBitmap), _extent.DisplayTransform);
    }



    protected override Renderer mapCreateRenderer(System.Type geomType)
    {

      return this.createRenderer(geomType);
    }




    protected override MapLegend mapLegend
    {
      get {return this.Legend;}
    }




    public Legend Legend
    {
      get { return (Legend)_legend; }
    }




    public Image draw()
    {
      return new Bitmap(10, 10);
    }

    //protected override object mapDraw()
    //{
    //  return this.draw();
    //}

  }

}
